package com.crl.module.loaders.workers
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.HTTPStatusEvent;
	import flash.events.IOErrorEvent;
	import flash.events.ProgressEvent;
	import flash.events.SecurityErrorEvent;
	import flash.net.URLRequest;

	public class Worker extends EventDispatcher implements ILoadWorker
	{
		protected var request:URLRequest;
		protected var loader:*;
		protected var paused:Boolean;
		protected var _data:*;
		public function Worker()
		{
		}
		
		public function load(request:URLRequest,autoStart:Boolean=false):void
		{
			request=request;
			if(autoStart)start();
		}
		
		public function start():void
		{
			loader.load(request);
			paused = false;
		}
		
		public function stop():void
		{
			try{
				loader.close();
			}catch(e:Error){
				trace(e);
			}
			paused = true;
		}
		
		public function pause():void
		{
			if(!paused)
			{
				stop();
			}
			else
			{
				start();
			}
		}
		
		
		protected function onOpen(event:Event):void{

		}
		protected function onProgress(event:ProgressEvent):void{
			
		}
		protected function onHTTPStatus(event:HTTPStatusEvent):void{
			
		}
		protected function onIOLoadError(event:IOErrorEvent):void{
			
		}
		protected function onSecurityError(event:SecurityErrorEvent):void{
			
		}
		protected function onComplete(event:Event):void{
			
		}
		
		public function get data():Object{
			return _data;
		}
		
	}
}